﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KPI.OrganizationDomain.Model.Entity;
using KPI.OrganizationDomain.Service;
using System.Data;


namespace KPI.WebApp.Employee
{
    public partial class CreateEmployee : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                OrganizationService employeeService = new OrganizationService();
                DataTable strLevel = employeeService.SelectEmployeeLevel();

                this.DownListLevel.DataSource = strLevel;
                this.DownListLevel.DataValueField = "EmployeeLevelID";
                this.DownListLevel.DataTextField = "Name";
                DownListLevel.DataBind();

                DataTable strTitle = employeeService.SelectEmployeeTitle();
                this.DownListTitle.DataSource = strTitle;
                this.DownListTitle.DataValueField = "EmployeeTitleID";
                this.DownListTitle.DataTextField = "Name";
                DownListTitle.DataBind();
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            KPI.OrganizationDomain.Model.Entity.Employee employeeDto = new OrganizationDomain.Model.Entity.Employee();
            if (txtBxBirthday.Text.Trim() != null)
            {
                employeeDto.Birthday = Convert.ToDateTime(txtBxBirthday.Text.ToString());
            }
            if (TxtBxEmployeeID.Text.Trim() != null)
            {
                employeeDto.EmployeeID = Convert.ToInt32(TxtBxEmployeeID.Text.ToString());
            }
            employeeDto.CreatedDate = DateTime.Now;
            employeeDto.Email = TxtBxEmail.Text.ToString();
            //employeeDto.Department = TxtBxDepartment.Text.ToString();
            employeeDto.Email = TxtBxEmail.Text.ToString();
            employeeDto.FirstName = txtBxFirstName.Text.ToString();
            if (txtBxFirstWorkingDate.Text.Trim() != null)
            {
                employeeDto.FirstWorkingDate = Convert.ToDateTime(txtBxFirstWorkingDate.Text.ToString());
            }
            employeeDto.LastName = txtBxLastName.Text.ToString();
            employeeDto.LoginName = TxtBxLoginName.Text.ToString();
            employeeDto.MobilePhoneNumber = TxtBxMPhoneNumber.Text.ToString();
            employeeDto.TelephoneNumber = TxtBxTelephoneNumber.Text.ToString();
            EmployeeLevel employLevel = new EmployeeLevel();
            employLevel.EmployeeLevelID = Convert.ToInt32(this.DownListLevel.SelectedValue);
            employeeDto.Level = employLevel;

            EmployeeTitle employeeTitle = new EmployeeTitle();
            employeeTitle.EmployeeTitleID = Convert.ToInt32(this.DownListTitle.SelectedValue);
            employeeDto.Title = employeeTitle;

            OrganizationService employeeService = new OrganizationService();
            employeeService.CreateEmployee(employeeDto);

        }
    }
}